package com.yuliang.ai.request;

import com.alibaba.fastjson.JSONObject;
import com.yuliang.ai.logic.LoginOperationLogic;
import com.yuliang.utils.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author Huangkai
 */
@Slf4j
@Component
public class LoginUtils {

    public static void loginOperation(String userName, String password){
        String responseContent = LoginOperationLogic.login(userName, password);
        JSONObject resultObject = JSONObject.parseObject(responseContent);
        log.info("登陆信息{}", resultObject);
        if(resultObject.getInteger("code") == -100){
            return;
        }
        Result result = JSONObject.toJavaObject(resultObject, Result.class);
        //表示成功
        if(result.getCode() == 10000){
            String token = result.getData().getToken();
            //设置token的值
            RedisUtils.set("token", token);
        }
    }

}


